<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket Client</title>
</head>
<body>
<h1>WebSocket Client</h1>
<div id="messages"></div>
<input type="text" id="messageInput" placeholder="Type a message..." />
<button id="sendButton">Send</button>
<script>
    const ws = new WebSocket('ws://192.168.1.110:7096');
    ws.onopen = () => {
        console.log('Connected to the WebSocket server');
    };
    ws.onmessage = (event) => {
        const messages = document.getElementById('messages');
        console.log(event.data)
        messages.innerHTML += `<p>${event.data}</p>`;
    };
    ws.onclose = () => {
        console.log('Disconnected from the WebSocket server');
    };
    ws.onerror = (error) => {
        console.error('WebSocket error:', error);
    };
    const sendButton = document.getElementById('sendButton');
    const messageInput = document.getElementById('messageInput');
    sendButton.addEventListener('click', () => {
        const message = messageInput.value;
        ws.send(JSON.stringify({text:message}));
        messageInput.value = '';
    });
</script>
</body>
</html>